<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

  <xsl:strip-space elements="*" />
  <xsl:template match="/">
    <xsl:for-each select="//StaffConsentItems">
      <xsl:call-template name="HeaderTemplate" />
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="HeaderTemplate">
    <fo:root >
      <fo:layout-master-set>
        <fo:simple-page-master master-name='page' margin='0.5cm'>
          <fo:region-body margin='0.5cm' margin-bottom='0.5cm' margin-top='1.5cm' region-name='body' />
          <fo:region-after extent='0.5cm' region-name="footer" />
          <fo:region-before region-name="header" />
          <fo:region-start extent='0.5cm'/>
          <fo:region-end extent='0.5cm'/>
        </fo:simple-page-master>
      </fo:layout-master-set>

      <fo:page-sequence master-reference="page">
        <fo:static-content flow-name='footer'>
          <fo:block text-align='center'>
            Page <fo:page-number/> of <fo:page-number-citation ref-id='last-page'/>
          </fo:block >
        </fo:static-content>
        
      <fo:static-content flow-name='header'>
          <fo:block text-align='right'>
            <xsl:variable name='Logo'>
              <xsl:value-of select="../LogoLocation"/>
            </xsl:variable>
            <fo:external-graphic scaling='uniform' content-width="100%" content-height="100%" src="url({$Logo})" />
          </fo:block>
      </fo:static-content>

        <fo:flow flow-name='body'>
          <fo:block linefeed-treatment='preserve' white-space-treatment='preserve' white-space-collapse='false' font-family='times new roman' font-size='10pt'/>
          <fo:block space-before='0.5cm'/>
          <fo:table>
            <fo:table-body>
              <fo:table-row>
                <fo:table-cell border='1pt' padding='1pt'>
                  <fo:block font-family='Helvetica' font-size='10pt'  text-align='left'>
                    Title: <fo:inline font-weight='bold'>
                      <xsl:value-of select="../Title"/>
                    </fo:inline>
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
            </fo:table-body>
          </fo:table>          
          <fo:table>
            <fo:table-body>
              <fo:table-row>
                <fo:table-cell border='1pt' padding='1pt'>
                  <fo:block font-family='Helvetica' font-size='10pt'  text-align='left'>
                    PI Name: <fo:inline font-weight='bold'>
                      <xsl:value-of select="../PIName"/>
                    </fo:inline>
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
              <fo:table-row>
                <fo:table-cell border='1pt' padding='1pt'>
                  <fo:block font-family='Helvetica' font-size='10pt'  text-align='left'>
                    Protocol #: <fo:inline font-weight='bold'>
                      <xsl:value-of select="../ProtocolNumber"/>
                    </fo:inline>
                  </fo:block>
                </fo:table-cell>                               
              </fo:table-row>                                          
            </fo:table-body>
          </fo:table>
          <fo:block space-before='0.5cm'/>
        <xsl:call-template name="ItemTemplate" />
        
		<fo:table>
			<fo:table-body>
				<fo:table-row>				             
					<fo:table-cell border='1pt' padding='1pt'>                  
					</fo:table-cell>						
				</fo:table-row>
			</fo:table-body>
		</fo:table> 					              
		<fo:table>
			<fo:table-body>
				<fo:table-row>				             
					<fo:table-cell border='1pt' padding='1pt'>                  
					</fo:table-cell>						
				</fo:table-row>
			</fo:table-body>
		</fo:table> 	    
		<fo:table>
			<fo:table-body>
				<fo:table-row>				
					<fo:table-cell border='1pt' padding='1pt'>
						<fo:block font-family='Helvetica' font-size='10pt'  text-align='left'>
							Authenticated: <fo:inline font-weight='bold'>
							<xsl:value-of select="../ApprovedBy"/>
							</fo:inline>
						</fo:block>
					</fo:table-cell>              							
				</fo:table-row>
				<fo:table-row>                               
					<fo:table-cell border='1pt' padding='1pt'>
						<fo:block font-family='Helvetica' font-size='10pt'  text-align='left'>
							Authenticated On: <fo:inline font-weight='bold'>
							<xsl:value-of select="../Today"/>
							</fo:inline>
						</fo:block>
					</fo:table-cell>                                
				</fo:table-row>
			</fo:table-body>
		</fo:table>	
    <fo:block id='last-page'/>
    </fo:flow>
    </fo:page-sequence>
    </fo:root>
  </xsl:template>
  
  <xsl:template name="ItemTemplate">
   <fo:table>
    <fo:table-body>
      <xsl:for-each select="StaffConsentItem">
        <fo:table-row>
          <xsl:variable name="type">
            <xsl:value-of select="Type"/>
          </xsl:variable>
          <xsl:variable name="status">
            <xsl:value-of select="Status"/>
          </xsl:variable>
          <xsl:if test="$type='CHECKBOX' or $type='RADIOBUTTON'">
            <xsl:if test="$status='CHECKED'">
              <fo:table-cell border='1pt white' padding='2pt'>
                <fo:block>
                  <fo:inline font-family="ZapfDingbats" font-weight='bold'>&#x2714;</fo:inline>
                  <fo:inline font-family='Helvetica' font-size='9pt' text-align='left'>
                    <xsl:value-of select="Content"/>
                  </fo:inline>
                </fo:block>
              </fo:table-cell>
            </xsl:if>
            <xsl:if test="$status='NA'">
              <fo:table-cell border='1pt white' padding='2pt'>
                <fo:block font-family='Helvetica' font-size='9pt' text-align='left'>
                  <xsl:value-of select="Content"/>
                </fo:block>
              </fo:table-cell>
            </xsl:if>
          </xsl:if>
          <xsl:if test="$type='HEADING'">
            <fo:table-cell border='1pt white' padding='2pt'>
              <fo:block font-family='Helvetica' font-size='10pt' font-weight='bold' text-align='left'>
                <xsl:value-of select="Content"/>
              </fo:block>
            </fo:table-cell>
          </xsl:if>
          <xsl:if test="$type='TEXT'">
            <fo:table-cell border='1pt white' padding='2pt'>
              <fo:block font-family='Helvetica' font-size='9pt' text-align='left'>
                <xsl:value-of select="Content"/>
              </fo:block>
            </fo:table-cell>
          </xsl:if>
        </fo:table-row>
      </xsl:for-each>
    </fo:table-body>
    </fo:table>
  </xsl:template>    
  
    
</xsl:stylesheet>